
cmake_minimum_required (VERSION 3.20.0)

# set cmake
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED true)

set(IS_DEBUG FALSE)
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
if ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "DEBUG")
	set(IS_DEBUG TRUE)
endif()

# 设置是否是开发环境宏
if (IS_DEBUG) 
    add_definitions(-DDEBUG)
else()
    add_definitions(-DRELEASE)
endif()

#set(LUAGUI_EXTERNALS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../externals)
# embed-resource
#add_subdirectory(${LUAGUI_EXTERNALS_DIR}/embed-resource embed-resource)

# set project name
project(LuaGui)

# project
#list(APPEND LUAGUI_CORE_SRC_FILES
#    ${CMAKE_CURRENT_SOURCE_DIR}/src/Application.cpp
#    ${CMAKE_CURRENT_SOURCE_DIR}/src/Common.cpp
#    ${CMAKE_CURRENT_SOURCE_DIR}/src/FileSystem.cpp
#    ${CMAKE_CURRENT_SOURCE_DIR}/src/Util.cpp
#)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/core DIR_CORE_SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/luaapp DIR_LUAAPP_SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/net DIR_NET_SRCS)
add_library(${PROJECT_NAME} ${DIR_CORE_SRCS} ${DIR_NET_SRCS} ${DIR_LUAAPP_SRCS})

#if (SERVER)
#    add_library(${PROJECT_NAME} ${LUAGUI_CORE_SRC_FILES})
#else()
#    add_library(${PROJECT_NAME} ${DIR_CORE_SRCS} ${DIR_NET_SRCS} ${DIR_LUAAPP_SRCS})
#endif()

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/common)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../externals/embed-resource)

#include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/option.cmake)
if (ANDROID)
	include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/android.cmake)
else()
	include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/libs.cmake)
endif()


# script directory
if (NOT DEFINED LUAGUI_SCRIPT_DIRECTORY) 
    if (IS_DEBUG)
        set(LUAGUI_SCRIPT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
        add_definitions(-DLUAGUI_SCRIPT_DIRECTORY="${LUAGUI_SCRIPT_DIRECTORY}")
    endif()
else()
    add_definitions(-DLUAGUI_SCRIPT_DIRECTORY="${LUAGUI_SCRIPT_DIRECTORY}")
endif()

# asset directory
if (NOT DEFINED LUAGUI_ASSET_DIRECTORY) 
    if (IS_DEBUG)
        set(LUAGUI_ASSET_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../assets)
        add_definitions(-DLUAGUI_ASSET_DIRECTORY="${LUAGUI_ASSET_DIRECTORY}")
    endif()
else()
    add_definitions(-DLUAGUI_ASSET_DIRECTORY="${LUAGUI_ASSET_DIRECTORY}")
endif()

# 字体名称
set(FONT_FILENAME "DroidSansFallback.ttf")
add_definitions(-DFONT_FILENAME="${FONT_FILENAME}")
# font filepath
if (NOT DEFINED LUAGUI_FONT_FILEPATH) 
    if (IS_DEBUG)
        set(LUAGUI_FONT_FILEPATH ${CMAKE_CURRENT_SOURCE_DIR}/../assets/fonts/${FONT_FILENAME})
        add_definitions(-DLUAGUI_FONT_FILEPATH="${LUAGUI_FONT_FILEPATH}")
    endif()
else()
    add_definitions(-DLUAGUI_FONT_FILEPATH="${LUAGUI_FONT_FILEPATH}")
endif()

# log filepath
if (NOT DEFINED LUAGUI_LOG_FILEPATH) 
    if (IS_DEBUG)
        set(LUAGUI_LOG_FILEPATH ${CMAKE_CURRENT_SOURCE_DIR}/../log.txt)
        add_definitions(-DLUAGUI_LOG_FILEPATH="${LUAGUI_LOG_FILEPATH}")
    endif()
else()
    add_definitions(-DLUAGUI_LOG_FILEPATH="${LUAGUI_LOG_FILEPATH}")
endif()

# 自动加载字体
if (AUTO_LOAD_FONT_FILE) 
    add_definitions(-DAUTO_LOAD_FONT_FILE)
endif()

# 使用字体库
if (AUTO_LOAD_FONT_DATA)
    add_definitions(-DAUTO_LOAD_FONT_DATA)
	add_subdirectory(${LUAGUI_EXTERNALS_DIR}/luagui-fontdata luagui-fontdata)
	target_link_libraries(${PROJECT_NAME} PUBLIC luagui-fontdata)
endif()

# 自动加载脚本
if (AUTO_LOAD_SCRIPT) 
    add_definitions(-DAUTO_LOAD_SCRIPT)
endif()

if (AUTO_LOAD_SCRIPT_DATA) 
	add_definitions(-DAUTO_LOAD_SCRIPT_DATA)
	add_subdirectory(${LUAGUI_EXTERNALS_DIR}/luagui-script luagui-script)
	target_link_libraries(${PROJECT_NAME} PUBLIC luagui-script)
endif()


# include libs
# include(${CMAKE_CURRENT_SOURCE_DIR}/libs.cmake)

